#include <iostream>
#include <ext/numeric>

#include "zService.h"
#include "zNetService.h"
//#include "zSocket.h"
//#include "zTCPServer.h"
//#include "zThread.h"
//#include "zTCPTaskPool.h"

zNetService *zNetService::instance=NULL;

bool zNetService::init(unsigned short port)
{
	if(!zService::init())
		return false;

	tcpServer = new zTCPServer(serviceName);
	if(tcpServer && tcpServer->bind(serviceName,port))
		return true;
	return false;
}

bool zNetService::serviceCallBack()
{
	struct sockaddr_in addr;
	int retcode = tcpServer->accept(&addr);
	if(retcode >= 0)
		newTCPTask(retcode,&addr);
	return true;
}

void zNetService::final()
{
	logger->debug("%s",__PRETTY_FUNCTION__);
	delete tcpServer;
}
